import { basicsRouterMap, asyncRouterMap } from '@/router/router-map'

const router = {
    state: {
        routers: basicsRouterMap,
        addRouters: []
    },

    getters: {
        addRouters: state => state.addRouters
    },

    mutations: {
        SET_ROUTERS: (state, routers) => {
            state.addRouters = routers
            state.routers = basicsRouterMap.concat(routers)
        }
    },

    actions: {
        generateRoutes ({ commit }, rules) {
            return new Promise((resolve, reject) => {
                // console.log('rules-->', rules)
                // 根据返回权限列表过滤路由
                let accessedRouters = asyncRouterMap
                // let accessedRouters = getAccessRouters(asyncRouterMap, roles)
                commit('SET_ROUTERS', accessedRouters)
                resolve()
            })
        }
    }
}

export default router
